import Vue from 'vue';
var mpheader = require("../components/mpheader.js");
var dt = require("../components/dateTime.js");
var wl = require("../components/winLocation.js");

var recordVue;
var openid, prdtNo;
var min_cnt = 0;
var max_cnt = 30;
var recordData = [];
$(document).ready(function() {
    initPage();
});
var orderStateMap = {
    "01": "待交易",
    "02": "申请成功,已划付",
    "03": "申请成功,已划付",
    "04": "已退货",
    "05": "划付失败,已撤销",
    "99": "分期失败"
};

// 处理数据
function manipulationData(lfqorderInfo) {
    for (var i = 0, l = lfqorderInfo.length; i < l; i++) {
        lfqorderInfo[i].formatDate = dt.getDateStrFormate1(lfqorderInfo[i].serial_no_time, "date");
        lfqorderInfo[i].stage_msg = orderStateMap[lfqorderInfo[i].order_state];
        if (lfqorderInfo[i].order_state == 2 || lfqorderInfo[i].order_state == 3) {
            lfqorderInfo[i].pngName = "../images/creditLoan/chenggong_icon.png";
        } else {
            lfqorderInfo[i].pngName = "../images/creditLoan/sb_icon.png";
        }
    }

    recordVue.rateArray = lfqorderInfo;
}

// 设置记录父标签的高度
function setRecordParentHeight() {
    var wih = window.innerHeight;
    var rph = (wih - 44) + "px";
    $("#loanInquiry_page>.page__bd").css("height", rph);
}


// 取交易记录
function getRecordData() {
    var rdParameter = {
        open_id: openid,
        prdt_no: prdtNo,
        min_count: min_cnt,
        max_count: max_cnt,
        servlet_type: "query_order",
        now: new Date().getTime()
    };
    $.post(LFQCreateOrderServlet, rdParameter, function(rddata) {
        rddata = JSON.parse(rddata);
        if (rddata.lft_orderinfo_response && rddata.lft_orderinfo_response.lfqorderInfo_arrays.lfqorderInfo) {
            manipulationData(rddata.lft_orderinfo_response.lfqorderInfo_arrays.lfqorderInfo);
        }


    });
}
// 
function craeteRecordVue() {
    var mheder1 = mpheader.getMPheader({
        "titleText": "信用贷款查询"
    }, function() {

    });

    recordVue = new Vue({
        el: "#loanInquiry_page",
        data: {
            rateArray: recordData,


        },
        computed: {

        },
        beforeMount: function() {
            console.log("amountslect beforeMount 渲染前");
        },
        mounted: function() {
            console.log("amountslect mounted 加载完");
            getRecordData();
        },
        components: {
            "mpheader": mheder1
        },
        methods: {
            "toDetails": function(event) {
                var serialNo = $(event.target).parents(".weui-cells").attr("data-serial");
                location.href = "./details.html?openid=" + openid + "&serialNo=" + serialNo;
            }
        }
    });
}

// 初始化变量
function initValue() {
    openid = wl.QueryString.GetValue("openid");
    prdtNo = wl.QueryString.GetValue("prdtNo");
}

function initPage() {
    wl.checkBrowser();
    wl.QueryString.Initial();
    initValue();
    setRecordParentHeight();

    craeteRecordVue();

}